// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    material: cc.Material = null;
 
    b:number = 1.0;
    bMax: number = 1.0;
    bMin: number = -1.0;
    loopWidth: number = 0.1;


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
         //获取材质
         this.material = this.node.getComponent(cc.Sprite).getMaterial(0);
         //设置参数k
         this.material.setProperty("k", 0);
        //  for (let i = 0; i< 9; i++) {
        //     this.loopWidth += 0.1;
        //     cc.tween(this.node)
        //     .delay(1)
        //     .call(()=>{
        //     })
        //     .start();
        //  }
         this.schedule(()=>{
            this.loopWidth += 0.1;
            console.log('sche widths31', this.loopWidth);
            if(this.loopWidth >= 1) {
                console.log('sche widths41', this.loopWidth);
                this.schedule(()=>{
                    console.log('sche widths1', this.loopWidth);
                    if (this.loopWidth <= 0) return;
                    this.loopWidth -= 0.1;
                    console.log('sche widths2', this.loopWidth);
                    this.material.setProperty('width', this.loopWidth);
                    
                },1,10,0);
                return;
            };
            this.material.setProperty('width', this.loopWidth);

         },1,9,0);
         console.log('sche widths', this.loopWidth);
         if (this.loopWidth == 1) {
            
         }
         
 
    }

    update (dt) {
        // if(this.node.active && this.material != null){
        //     //设置参数b
        //     this.material.setProperty("b", this.b);
        // }
        // this.b -= 0.03;
        // if(this.b < this.bMin)this.b = this.bMax;
    }

}
